import { defineStore } from "pinia";

interface UserInfo {
  phone: string;
}

const userInfo: UserInfo = {
  phone: "",
};

interface UserState {
  userInfo: UserInfo;
  token: string;
}

export const useUserStroe = defineStore("user", {
  state: () => ({
    userInfo: userInfo,
    token:
      "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJpc3N1c2VyIiwiYXVkIjoiYXVkaWVuY2UiLCJ1c2VyX2lkIjoiNzQxOSIsInRva2VuX3R5cGUiOiJhY2Nlc3NfdG9rZW4iLCJjbGllbnRfaWQiOiJoNSIsImV4cCI6MTc0NjMzNTYzMCwibmJmIjoxNzQ1NzMwODMwfQ.kbl-ylONdr3lPUdwC0jMCLxrjfRIho8xob11WXKWow6WWrbPOLayIm8LxnVSMvo__Ivu5sMu7Z2VBlG0V1SbVA",
  }),

  persist: {
    enabled: true,
  },

  getters: {
    getToken(): UserState["token"] {
      return this.token;
    },
  },
  actions: {
    setToken(token: string) {
      this.token = token;
    },
    setUserInfo(info: UserInfo) {
      this.userInfo = info;
    },
  },
});
